/*
 * esp8266.c
 *
 *  Created on: 2017年7月30日
 *      Author: Case
 */

#ifndef CG_SRC_ESP8266_C_
#define CG_SRC_ESP8266_C_

#include "r_cg_sci.h"
#include "esp8266.h"
#include "delay.h"
#include "const_esp8266.h"
#include "pid.h"
void	Esp8266_Init(void)
{
	Delay_ms(1);
	R_SCI1_Serial_Send_Data(esp8266_at_cipmux,13);
	Delay_ms(1);
	R_SCI1_Serial_Send_Data(esp8266_at_cipserver,21);
	Delay_ms(1);
}

void	Esp8266_Send_Data(uint8_t const  *  tx_buf, uint16_t tx_num)
{
	char esp8266_at_cipsend[18] = {"AT+CIPSEND=0,30\r\n"};
	esp8266_at_cipsend[13] = tx_num/10+48;
	esp8266_at_cipsend[14] = tx_num%10+48;
	R_SCI1_Serial_Send_Data(esp8266_at_cipsend,17);
	Delay_ms(1);
	R_SCI1_Serial_Send_Data(tx_buf, tx_num);
	Delay_ms(1);
}

void	Esp8266_Send_Height(int height)
{
	char		Tx_height[13] = {"height:"};
	Tx_height[7] = height/1000 + 48;
	Tx_height[8] = height%1000/100 + 48;
	Tx_height[9] = height%100/10 + 48;
	Tx_height[10] = height%10 + 48;
	Tx_height[11] = '\t';
	Esp8266_Send_Data(Tx_height,12);
}

void	Esp8266_Send_Pass3(AirPass air)
{
	char	Tx_pass3[12] = {"pass3:"};
	Tx_pass3[6] = air.pass_3/1000 + 48;
	Tx_pass3[7] = air.pass_3%1000/100 + 48;
	Tx_pass3[8] = air.pass_3%100/10 + 48;
	Tx_pass3[9] = air.pass_3%10 + 48;
	Tx_pass3[10] = '\t';
	Esp8266_Send_Data(Tx_pass3,11);
}

void	Esp8266_Send_PID(int	pid)
{
	char	Tx_pass3[13] = {"incpid:"};
	Tx_pass3[7] = pid/1000 + 48;
	Tx_pass3[8] = pid%1000/100 + 48;
	Tx_pass3[9] = pid%100/10 + 48;
	Tx_pass3[10] = pid%10 + 48;
	Tx_pass3[11] = '\n';
	Esp8266_Send_Data(Tx_pass3,12);
}

void	Bule_Send_Height(int height)
{
	char		Tx_height[13] = {"height:"};
	Tx_height[7] = height/1000 + 48;
	Tx_height[8] = height%1000/100 + 48;
	Tx_height[9] = height%100/10 + 48;
	Tx_height[10] = height%10 + 48;
	Tx_height[11] = '\t';
	R_SCI1_Serial_Send_Data(Tx_height,12);
}

void	Bule_Send_Pass3(AirPass air)
{
	char	Tx_pass3[12] = {"pass3:"};
	Tx_pass3[6] = air.pass_3/1000 + 48;
	Tx_pass3[7] = air.pass_3%1000/100 + 48;
	Tx_pass3[8] = air.pass_3%100/10 + 48;
	Tx_pass3[9] = air.pass_3%10 + 48;
	Tx_pass3[10] = '\t';
	R_SCI1_Serial_Send_Data(Tx_pass3,11);
}


void	Bule_Send_PID(int	pid)
{
	char	Tx_pass3[13] = {"incpid:"};
	Tx_pass3[7] = pid/1000 + 48;
	Tx_pass3[8] = pid%1000/100 + 48;
	Tx_pass3[9] = pid%100/10 + 48;
	Tx_pass3[10] = pid%10 + 48;
	Tx_pass3[11] = '\n';
	R_SCI1_Serial_Send_Data(Tx_pass3,12);
}

#endif /* CG_SRC_ESP8266_C_ */
